package com.qf.dao.impl;

import com.qf.bean.Menu;
import com.qf.bean.Users;
import com.qf.dao.MenuUsersDao;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 2019/12/7
 * Administrator
 * springboot1207
 * 面向对象面向君  不负代码不负卿
 */
@Repository
public class MenuUsersDaoImpl implements MenuUsersDao {
    @Resource(name="oneTemp")
    private JdbcTemplate jdbcTemplateone;//chaoshi  数据库
    @Resource(name="twoTemp")
    private JdbcTemplate jdbcTemplatetwo;//hunan 数据库


    @Override //连接chaoshi
    public List<Users> findusers() {
        List<Users> usersList = jdbcTemplateone.query("select * from users", new RowMapper<Users>() {
            @Override
            public Users mapRow(ResultSet resultSet, int i) throws SQLException {
                Users users = new Users();
                users.setUserId(resultSet.getInt("userid"));
                users.setUserName(resultSet.getString("username"));
                return users;
            }
        });
        return usersList;
    }

    @Override  //hunan数据库
    public List<Menu> findMenus() {
        List<Menu> menuList = jdbcTemplatetwo.query("select * from menu", new RowMapper<Menu>() {
            @Override
            public Menu mapRow(ResultSet resultSet, int i) throws SQLException {
                Menu menu = new Menu();
                menu.setMenuid(resultSet.getInt("menuid"));
                menu.setMenuname(resultSet.getString("menuname"));
                return menu;
            }
        });
        return menuList;
    }
}
